package com.arithmetic.list;

import lombok.Data;

/**
 * @author chenyichang
 * @date 2022/8/7
 */
@Data
public class ListNode {

    int val;
    ListNode next;

    public ListNode() {

    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    public ListNode(int val) {
        this.val = val;
    }

    /**
     * 重写toString，将链表的值遍历出来
     *
     * @return
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(this.val).append(",");
        ListNode temp = next;
        while (temp != null) {
            sb.append(temp.val).append(",");
            temp = temp.next;
        }
        return sb.toString();
    }
}
